---
title: 'Prompt with Guardrails'
description: 'Learn how to implement validation guardrails to ensure AI outputs meet quality standards and safety requirements'
---

## What are Prompt Guardrails?

Prompt guardrails are validation mechanisms that monitor and control AI outputs to ensure they meet specific quality, safety, and compliance standards. Unlike constraint-based prompting that sets boundaries upfront, guardrails act as continuous validators that check outputs after generation and can trigger corrections or regeneration when standards aren't met.

## Why Use Prompt Guardrails?

- **Quality Assurance**: Ensures outputs consistently meet predefined standards
- **Safety Compliance**: Prevents harmful, inappropriate, or policy-violating content
- **Iterative Improvement**: Automatically refines outputs through validation loops
- **Confidence Building**: Provides measurable quality scores for output reliability
- **Risk Mitigation**: Catches and corrects potential issues before user delivery
- **Automated Workflows**: Enables fully automated content generation with quality control
- **Scalable Standards**: Maintains consistent quality across high-volume operations

## Basic Implementation in Latitude

Here's a simple guardrail example for content validation:

```markdown Basic Content Guardrails
---
provider: OpenAI
model: gpt-4o
temperature: 0.7
---

# Content Generator with Basic Guardrails

Generate content for: {{ topic }}

## Requirements:
- Professional tone
- Factually accurate
- 200-300 words
- No controversial statements

## Content:
[Generate content here]

## Self-Validation:
Rate this content on a scale of 1-10 for:
- Professional tone:
- Factual accuracy:
- Length appropriateness:
- Controversy avoidance:

If any score is below 7, regenerate the content with improvements.
```

## Advanced Implementation with Agent Validators

The most effective guardrails use dedicated validator agents that can provide objective, measurable feedback:

<CodeGroup>
```markdown Email Rewriter with Guardrails
---
provider: OpenAI
model: gpt-4.1
maxSteps: 10
type: agent
agents:
  - validator
---

Rewrite the email below in a more upbeat tone (remain concise):

{{ email }}

Here are two examples of dull emails and their upbeat counterparts:

**Dull Email 1:**
Subject: Meeting Confirmation

Hi Team,

This is to confirm our meeting scheduled for Thursday at 3 PM. Please be on time.

Regards,

Alex

**Upbeat Email 1:**
Subject: Exciting Meeting Ahead!

Hey Team!

I'm thrilled to confirm our meeting this Thursday at 3 PM! Let's make sure to bring our best ideas and energy!
Can't wait to see you all there!

Cheers,

Alex

**Dull Email 2:**
Subject: Project Update

Dear Colleagues,

I wanted to inform you that the project is still in progress. We will update you when we have more information.

Sincerely,

Jordan

**Upbeat Email 2:**
Subject: Exciting Project Update!

Hello Team!

I'm excited to share that our project is moving along nicely! Stay tuned for more updates as we continue to make progress!

Best,

Jordan

After rewriting the email, check with the validator tool to see if you did well. Complete the task once the validator returns a score >0.85. If the score is lower, try rewriting the email and checking with the validator again.

Return only the rewritten email.
```
```markdown validator
---
provider: OpenAI
model: gpt-4o
schema:
  type: object
  properties:
    score:
      type: number
  required:
    - score
  additionalProperties: false
type: agent
---

Please evaluate if the following email was rewritten to a more upbeat tone. Make sure the tone is still professional and the email doesn't overuse exclamation points

Original:
{{ original_email }}

Rewritten:
{{ rewritten_email }}

Return a score from 0 to 1.
```
</CodeGroup>

In this advanced example:

1. **Quality Threshold**: The system only accepts outputs scoring above 0.85
2. **Iterative Refinement**: Low scores trigger automatic regeneration
3. **Objective Validation**: A dedicated validator agent provides measurable feedback
4. **Structured Output**: The validator returns a standardized score format
5. **Professional Balance**: Guardrails prevent over-enthusiasm while ensuring upbeat tone

## Best Practices for Prompt Guardrails

### Threshold Management
- **Conservative Thresholds**: Start with higher thresholds (0.8-0.9) for critical applications
- **Adaptive Thresholds**: Lower thresholds for creative tasks, higher for factual content
- **Multiple Metrics**: Use composite scores rather than single metrics
- **Escalation Paths**: Define what happens when content consistently fails validation

### Validator Design
- **Specific Criteria**: Make validation criteria as specific and measurable as possible
- **Structured Output**: Use schemas to ensure consistent, parseable validator responses
- **Domain Expertise**: Design validators with relevant domain knowledge
- **Bias Prevention**: Include checks for common biases and blind spots

Prompt guardrails represent a crucial evolution in AI safety and quality assurance, enabling automated systems that maintain high standards while operating at scale. When combined with other techniques like constraint-based prompting and chain-of-thought reasoning, they create robust, reliable AI applications suitable for production environments.
